package com.fm.base.json.impl;

import com.fm.base.json.JsonNumber;
import com.fm.base.lang.DeepCloneable;

import java.math.BigDecimal;
import java.math.BigInteger;

public class BasicJsonNumber implements JsonNumber {
    BigDecimal number;

    public BasicJsonNumber(String number) {
        this(new BigDecimal(number));
    }

    public BasicJsonNumber(int number) {
        this(new BigDecimal(number));
    }

    public BasicJsonNumber(long number) {
        this(new BigDecimal(number));
    }

    public BasicJsonNumber(double number) {
        this(new BigDecimal(number));
    }

    public BasicJsonNumber(BigDecimal number) {
        this.number = number;
    }

    @Override
    public BasicJsonNumber clone() {
        return new BasicJsonNumber(new BigDecimal(number.toPlainString()));
    }

    @Override
    public boolean isIntegral() {
        throw new UnsupportedOperationException();
    }

    @Override
    public int intValue() {
        return number.intValue();
    }

    @Override
    public int intValueExact() {
        return number.intValueExact();
    }

    @Override
    public long longValue() {
        return number.longValue();
    }

    @Override
    public long longValueExact() {
        return number.longValueExact();
    }

    @Override
    public BigInteger bigIntegerValue() {
        return number.toBigInteger();
    }

    @Override
    public BigInteger bigIntegerValueExact() {
        return number.toBigIntegerExact();
    }

    @Override
    public double doubleValue() {
        return number.doubleValue();
    }

    @Override
    public BigDecimal bigDecimalValue() {
        return number;
    }

    @Override
    public ValueType getValueType() {
        return ValueType.NUMBER;
    }

    @Override
    public String toString() {
        return number.toPlainString();
    }
}
